package com.zenghus.controller;

import com.zenghus.demo.Index;
import com.zenghus.demo.User;
import com.zenghus.service.IndexService;
import com.zenghus.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author zenghu
 * @date 2018/5/4 10:20
 */
@Controller
@RequestMapping("/index")
public class IndexController {

    @Autowired
    IndexService indexService;

    @Autowired
    UserService userService;

    @RequestMapping("/index")
    public String index(String name,ModelMap model) throws Exception {
        model.addAttribute("greeting",indexService.getContext(name));
        List<Index> indexList=indexService.getIndex();
        for (Index i:indexList) {
            System.out.println(i);
        }
        User user=new User();
        user.setUsername("132");
        userService.add(user);
        System.out.println("asdf");
        System.out.println("asdf123");
        System.out.println("sadf");
        return "index/index";
    }

    @RequestMapping("/add")
    @ResponseBody
    public String add(){
        return indexService.testTransactional();
    }
}
